package com.stek.floaticon;

import java.util.ArrayList;

import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;

import com.google.android.gms.ads.AdView;
import com.stek.R;
import com.stek.base.BaseOverLayActivity;
import com.stek.utils.AdMode;
import com.stek.utils.Broadcast;
import com.stek.utils.CONFIG;

public class FloatActivity extends BaseOverLayActivity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_float);
		GridView gridView = (GridView) findViewById(R.id.grid);

		loadData(gridView);
		adView = (AdView) findViewById(R.id.admod);
		AdMode.init(adView);
	}

	private void loadData(GridView gridView) {
		ArrayList<Integer> resources = new ArrayList<Integer>();
		for (int i = 0; i < 32; i++) {
			resources.add(getResources().getIdentifier("ic_android" + i,
					"drawable", getPackageName()));
		}
		FloatAdapter adapter = new FloatAdapter(getApplicationContext(),
				resources);
		gridView.setAdapter(adapter);
		gridView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				CONFIG.FLOAT_ICON.setFloatIcon(getApplicationContext(),
						(Integer) parent.getAdapter().getItem(position));
				Broadcast.sendBroadcast(getApplicationContext(),
						CONFIG.BROADCAST.ACTION_FLOAT_ICON_RESOURCE_CHANGED);
			}
		});
	}

	@Override
	protected void initActionBar() {
		super.initActionBar();
		getSupportActionBar().setDisplayUseLogoEnabled(false);
		getSupportActionBar().setDisplayShowTitleEnabled(false);
		getSupportActionBar().setBackgroundDrawable(
				new ColorDrawable(getResources().getColor(R.color.transparent)));
	}
}
